package restlet.runtime;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class RESTModule {
	String name;
	String path;
	List<RESTResource> resources = new ArrayList<RESTResource>();
	Map<String,RESTResource> resourcesByURI = new HashMap<String,RESTResource>();

	public void compile(){
		resourcesByURI.clear();
		for (RESTResource resource : resources) {
			resourcesByURI.put(resource.getURI(),resource);
		}
	}
	
	public void remove(String URI)
	{
		RESTResource resource = resourcesByURI.get(URI);
		resources.remove(resource);
		resourcesByURI.remove(URI);
	}
	
	public void replace(String URI,RESTResource newResource)
	{
		RESTResource resource = resourcesByURI.get(URI);
		resources.remove(resource);
		resources.add(newResource);
		resourcesByURI.put(URI,newResource);
	}
	
	public void addResource(RESTResource newResource)
	{
		resources.add(newResource);
		resourcesByURI.put(newResource.getURI(),newResource);
	}
	
	public List<RESTResource> getResources() {
		return resources;
	}

	public void setResources(List<RESTResource> resources) {
		this.resources = resources;
	}

	public Map<String, RESTResource> getResourcesByURI() {
		return resourcesByURI;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}
}
